using System.Collections.Generic;
public class ListExt<T> : BaseObject, IClear
{
    public List<T> list;
    private int _count = 0;

    public ListExt(int capacity = 0)
    {
        list = new List<T>(capacity);
    }

    public void AddMul(T obj)
    {
        list.Add(obj);
        ++_count;
    }

    public void Add(T obj)
    {
        if (!Contains(obj))
        {
            list.Add(obj);
            ++_count;
        }
    }

    public T GetByIndex(int index)
    {
        return list[index];
    }

    public void Remove(T obj)
    {
        list.Remove(obj);
        _count = list.Count;
    }

    public void RemoveAt(int index)
    {
        if (list.Count > index)
        {
            list.RemoveAt(index);
            --_count;
        }
    }

    public T RemoveAtLast()
    {
        if (list.Count > 0)
        {
            T data = list[list.Count - 1];
            list.RemoveAt(list.Count - 1);
            --_count;
            return data;
        }
        return default(T);
    }

    public bool Contains(T obj)
    {
        return list.IndexOf(obj) >= 0;
    }

    public T GetAtLast()
    {
        if (list.Count > 0)
        {
            return list[list.Count - 1];
        }
        return default(T);
    }

    public T GetAtFirst()
    {
        if (list.Count > 0)
            return list[0];
        return default(T);
    }

    public int Count
    {
        get
        {
            return _count;
        }
    }

    public List<T> GetList(){
        return list;
    }

    public void Clear()
    {
        list.Clear();
        _count = 0;
    }

    public override void Dispose()
    {
        base.Dispose();
        Clear();
        list = null;
    }

}
